class Query {
  /**
   * @param {Object} geom 通过交互式的画笔拿到的对象 type = 'Box'
   * @param {Object} service {docName,layerId}
   * @param {fnction} callback
   */

  static queryByGeom({ geom, service, callback }) {
    var queryStruct = new Zondy.Service.QueryFeatureStruct()
    //是否包含几何图形信息
    queryStruct.IncludeGeometry = true
    //是否包含属性信息
    queryStruct.IncludeAttribute = true
    //是否包含图形显示参数
    queryStruct.IncludeWebGraphic = false
    //创建一个用于查询的区
    var geomObj = new Zondy.Object.Polygon()
    geomObj.setByOL(geom)
    //指定查询规则
    var rule = new Zondy.Service.QueryFeatureRule({
      //是否将要素的可见性计算在内
      EnableDisplayCondition: false,
      //是否完全包含
      MustInside: false,
      //是否仅比较要素的外包矩形
      CompareRectOnly: false,
      //是否相交
      Intersect: true,
    })
    //实例化查询参数对象
    var queryParam = new Zondy.Service.QueryParameter({
      geometry: geomObj,
      resultFormat: 'json',
      struct: queryStruct,
      rule: rule,
    })
    //实例化地图文档查询服务对象
    var queryService = new Zondy.Service.QueryDocFeature(
      queryParam,
      service.docName,
      service.layerId,
      {
        ip: 'localhost',
        port: '6163', //访问IGServer的端口号，.net版为6163，Java版为8089
      }
    )
    //执行查询操作，querySuccess为查询回调函数
    queryService.query(callback)
  }
  /* 根据属性查询 核心where判断 */
  static queryBySql({ where, service, callback }) {
    var queryStruct = new Zondy.Service.QueryFeatureStruct()
    //是否包含几何图形信息
    queryStruct.IncludeGeometry = true
    //是否包含属性信息
    queryStruct.IncludeAttribute = true
    //是否包含图形显示参数
    queryStruct.IncludeWebGraphic = false
    //实例化查询参数对象
    var queryParam = new Zondy.Service.QueryParameter({
      resultFormat: 'json',
      struct: queryStruct,
    })
    //queryParam.where = name;
    /* 设置查询条件 */
    queryParam.where = where
    /* 3.  */
    var queryService = new Zondy.Service.QueryDocFeature(
      queryParam,
      service.docName,
      service.layerId,
      {
        ip: 'localhost',
        port: '6163', //访问IGServer的端口号，.net版为6163，Java版为8089
      }
    )
    //执行查询操作，querySuccess为查询回调函数
    queryService.query(callback)
  }

  /* 根据鼠标点击事件传入坐标点进行动态查询 */
  /* 
  param MousePosition []
  */
  static queryByMousePosition({
    mouseposition,
    toleranceradius,
    service,
    callback,
  }) {
    //1. 初始化查询结构对象，设置查询结构包含几何信息
    var queryStruct = new Zondy.Service.QueryFeatureStruct()
    queryStruct.IncludeGeometry = true
    queryStruct.IncludeWebGraphic = true
    console.log(queryStruct)
    //指定查询规则
    var rule = new Zondy.Service.QueryFeatureRule({
      //是否将要素的可见性计算在内
      EnableDisplayCondition: false,
      //是否完全包含
      MustInside: false,
      //是否仅比较要素的外包矩形
      CompareRectOnly: false,
      //是否相交
      Intersect: true,
    })
    //2. 创建一个用于查询的点形状
    // 点击鼠标获取位置
    var pointObj = new Zondy.Object.Point2D(mouseposition[0], mouseposition[1])
    //设置点容差半径
    pointObj.nearDis = toleranceradius
    //3. 实例化查询参数对象
    var queryParam = new Zondy.Service.QueryParameter({
      geometry: pointObj,
      resultFormat: 'json',
      struct: queryStruct,
      rule: rule,
    })
    //4. 实例化地图文档查询服务对象
    var queryService = new Zondy.Service.QueryDocFeature(
      queryParam,
      service.docName,
      service.layerId,
      {
        ip: 'localhost',
        port: '6163', //访问IGServer的端口号，.net版为6163，Java版为8089
      }
    )
    //执行查询操作，querySuccess为查询回调函数
    queryService.query(callback)
  }
  static queryByLayer({ service, callback }) {
    var queryStruct = new Zondy.Service.QueryFeatureStruct()
    //是否包含几何图形信息
    queryStruct.IncludeGeometry = true
    //是否包含属性信息
    queryStruct.IncludeAttribute = true
    //是否包含图形显示参数
    queryStruct.IncludeWebGraphic = false
    //指定查询规则
    var rule = new Zondy.Service.QueryFeatureRule({
      //是否将要素的可见性计算在内
      EnableDisplayCondition: false,
      //是否完全包含
      MustInside: false,
      //是否仅比较要素的外包矩形
      CompareRectOnly: false,
      //是否相交
      Intersect: true,
    })
    //实例化查询参数对象
    var queryParam = new Zondy.Service.QueryParameter({
      resultFormat: 'json',
      struct: queryStruct,
      rule: rule,
    })
    queryParam.recordNumber = 10000
    var queryService = new Zondy.Service.QueryDocFeature(
      queryParam,
      service.docName,
      service.layerId,
      {
        ip: 'localhost',
        port: '6163', //访问IGServer的端口号，.net版为6163，Java版为8089
      }
    )

    //执行查询操作，querySuccess为查询回调函数
    queryService.query(callback)
  }
  static queryByFid({ FID, service, callback }) {
    /* 1、设置查询结构 */
    const queryStruct = new Zondy.Service.QueryFeatureStruct()
    queryStruct.IncludeGeometry = true
    queryStruct.IncludeWebGraphic = true
    /* 2、设置查询参数 */
    const queryParam = new Zondy.Service.QueryParameter({
      struct: queryStruct,
      objectIds: FID,
    })
    /* 3、调用查询服务 */
    const queryService = new Zondy.Service.QueryDocFeature(
      queryParam,
      service.docName,
      service.layerId,
      {
        ip: 'localhost',
        port: 6163,
      }
    )
    /* 4、回调 */
    queryService.query(callback)
  }
}

export { Query }
